package java111;

import java.util.Scanner;

public class Day20 {
    //https://ac.nowcoder.com/acm/contest/11214/A
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            long a = in.nextInt();
            long h = in.nextInt();
            long b = in.nextInt();
            long k = in.nextInt();
            long res = 0;
            while(h > 0 && k > 0){
                res += (a + b);
                h -= b;
                k -= a;
                if(h <= 0 && k > 0){
                    res += 10 * b;
                }
                if(k <= 0 && h > 0){
                    res += 10 * a;
                }
            }
            System.out.println(res);
        }
    }
    public static void main11(String[] args) {  // 时间复杂度O(1)
        Scanner in = new Scanner(System.in);
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            long a = in.nextInt(), h = in.nextInt(), b = in.nextInt(), k = in.nextInt();
            long res = 0, n = Math.min(h/b, k/a);
            res += (a + b) * n;
            h -= n * b;
            k -= n * a;
            if(h > 0 && k > 0){
                h -= b;
                k -= a;
                res += (a + b);
            }
            if(h > 0){
                res += 10 * a;
            }
            if(k > 0){
                res += 10 * b;
            }
            System.out.println(res);
        }
    }


    // https://www.nowcoder.com/practice/03d341fb6c9d42debcdd38d82a0a545c?tpId=182&tqId=34902&ru=/exam/oj
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            long[] arr = new long[n];
            long[] dp = new long[n+1];
            //dp[i+1]表示从 0 到 i 位置的子数组的和
            for(int i = 0; i < n; i++){
                arr[i] = in.nextInt();
                dp[i+1] = dp[i] + arr[i];
            }
            long res = Long.MIN_VALUE;
            for(int i = 0; i < n + 1; i++){
                for(int j = i+1; j < n + 1; j++){
                    long tmp = dp[j] - dp[i];
                    res = Math.max(tmp, res);
                }
            }
            System.out.println(res);
        }
    }


    // https://ac.nowcoder.com/acm/contest/10746/I
    public static void main3(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.next();
        int i = 1;
        for(; i < str.length(); i++){
            if(str.charAt(i) != str.charAt(0)){
                break;
            }
        }
        if(i == str.length()){
            System.out.println(0);
            return;
        }
        int left = 0, right = str.length() - 1;
        while(left < right){
            if(str.charAt(left++) != str.charAt(right--)){
                i = -1;
                break;
            }
        }
        if(i == -1) {
            System.out.println(str.length());
        } else {
            System.out.println(str.length()-1);
        }
    }
}
